package com.fzshang.shopping.api;

import com.fzshang.shopping.commen.service.XbxWxService;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 张子艺
 * @packge com.xbxkj.controller
 * @data 2019-06-04 17:42
 * @project Metaphysics
 */
@Controller
@RequestMapping("/")
public class WebsocketController {

//    @Autowired
//    WebSocketService webSocketService;
    @Autowired
XbxWxService xbxWxService;
    /**
     *  发送消息
     *
     * @param param
     * @throws Exception
     */
//    @MessageMapping("/downMsg")//@MessageMapping和@RequestMapping功能类似，用于设置URL映射地址，浏览器向服务器发起请求，需要通过该地址。
//    //  @SendTo("/topic/getResponse")
//    public void downMsg(String param) throws Exception {
//        List<String> users = Lists.newArrayList();
//        //获取 后台选中回复的账号
//        String json = Aes.aesDecrypt(param, Aes.KEY);
//        User user = JSONObject.parseObject(json, User.class);
//       // users.add(user.getAccount() + "");
//      //  userService.updateById(user);
//        webSocketService.send2Users(users, new WiselyResponse(JSONObject.toJSONString(user)));
//    }

    @RequestMapping(value = "/checkToken" )
    public void checkToken(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) throws Exception {
    WxMpService wxMpService= xbxWxService.getWxService();
    if(wxMpService.checkSignature(timestamp,nonce,signature)) {
        try {
            response.getWriter().print(echostr);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    }


}
